package com.sytech.power_bank.helper

import java.lang.reflect.UndeclaredThrowableException
/*

inline fun <T> catch(crossinline block: () -> T): () -> T {
    return { block(); };
}

inline fun <T> (() -> T).by(exceptionally: (Throwable) -> T): T {
    return only { exceptionally(it) }!!
}

inline fun <T : R, R> (() -> T).only(exceptionally: (Throwable) -> R): R? {
    try {
        return invoke();
    } catch(e: UndeclaredThrowableException) {
        return exceptionally(e.cause ?: e);
    } catch(e: Exception) {
        return exceptionally(e);
    }
}*/
fun Exception.real():Throwable{
   return when(this){
        is UndeclaredThrowableException->this.cause?:this
        else->this
    }
}